﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.Xml;
using System.Reflection;

namespace Wangzeran.CodeMaker.Core.Config
{
    /// <summary>
    /// 插件节点处理，基类
    /// </summary>
    public abstract class BasePlugInsSectionHandler : IConfigurationSectionHandler
    {

        /// <summary>
        /// 插件文件夹
        /// </summary>
        protected const string PlugInsPath = @"PlugIns\";
        /// <summary>
        /// 插件节点
        /// </summary>
        protected const string PlugInsNode = "plugIns";
        /// <summary>
        /// 类型属性
        /// </summary>
        protected const string TypeAttribute = "type";
        /// <summary>
        /// 插件类库的扩展名
        /// </summary>
        protected const string PlugInExt = ".dll";
        /// <summary>
        /// 程序集名称 属性标签
        /// </summary>
        protected const string AssemblyAttribute = "assembly";
        /// <summary>
        /// 插件完全限定名 属性标签
        /// </summary>
        protected const string FactoryAttribute = "factory";


        #region IConfigurationSectionHandler 成员

        public abstract object Create(object parent, object configContext, XmlNode section); 

        #endregion


        /// <summary>
        /// 获取插件DLL的绝对路径
        /// </summary>
        /// <param name="assemblyName">程序集名称</param>
        /// <returns></returns>
        protected string GetPlugInPath(string assemblyName)
        {
            string path = Assembly.GetExecutingAssembly().Location;
            path = path.Remove(path.LastIndexOf(@"\") + 1);
            return path + PlugInsPath + assemblyName + PlugInExt;
        }

    }
}
